﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace ElingOA6_Admin_DSJCJ.DAL
{
    /// <summary>
    /// 数据访问类:TaskAuthority
    /// </summary>
    public partial class TaskAuthority
    {
        public TaskAuthority()
        { }
        #region  BasicMethod

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ElingOA6_Admin_DSJCJ.Model.TaskAuthority GetModel(string FTaskClassCd, string FLogID, string FEntityNo, string FAuthorityType)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 FTaskClassCd,FLogID,FEntityNo,FAuthorityType from dbo.t_TaskAuthority ");
            strSql.Append(" where FTaskClassCd=@FTaskClassCd and FLogID=@FLogID and FEntityNo=@FEntityNo and FAuthorityType=@FAuthorityType ");
            SqlParameter[] parameters = {
					new SqlParameter("@FTaskClassCd", SqlDbType.NVarChar,3),
					new SqlParameter("@FLogID", SqlDbType.NVarChar,30),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FAuthorityType", SqlDbType.NVarChar,20)			};
            parameters[0].Value = FTaskClassCd;
            parameters[1].Value = FLogID;
            parameters[2].Value = FEntityNo;
            parameters[3].Value = FAuthorityType;

            ElingOA6_Admin_DSJCJ.Model.TaskAuthority model = new ElingOA6_Admin_DSJCJ.Model.TaskAuthority();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ElingOA6_Admin_DSJCJ.Model.TaskAuthority DataRowToModel(DataRow row)
        {
            ElingOA6_Admin_DSJCJ.Model.TaskAuthority model = new ElingOA6_Admin_DSJCJ.Model.TaskAuthority();
            if (row != null)
            {
                if (row["FTaskClassCd"] != null)
                {
                    model.FTaskClassCd = row["FTaskClassCd"].ToString();
                }
                if (row["FLogID"] != null)
                {
                    model.FLogID = row["FLogID"].ToString();
                }
                if (row["FEntityNo"] != null)
                {
                    model.FEntityNo = row["FEntityNo"].ToString();
                }
                if (row["FAuthorityType"] != null)
                {
                    model.FAuthorityType = row["FAuthorityType"].ToString();
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FTaskClassCd,FLogID,FEntityNo,FAuthorityType ");
            strSql.Append(" FROM dbo.t_TaskAuthority ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" FTaskClassCd,FLogID,FEntityNo,FAuthorityType ");
            strSql.Append(" FROM dbo.t_TaskAuthority ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM dbo.t_TaskAuthority ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.FAuthorityType desc");
            }
            strSql.Append(")AS Row, T.*  from dbo.t_TaskAuthority T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

   
        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}

